<?php
if($p_data){

    $old = $session->user()->getGroupList();

    foreach($p_data as $k => $p){
        if(!is_array($p)) continue;
        unset($old[$k]);
        $old[$k] = $p;
        $session->user()->setGroupPerms($k,$old[$k]);
    }

}

$permlist = array(
    "modules" => array(),
    "pages" => array(), 
    "system" => array()
);
if (!is_array($modules = glob(_MODULEPATH_ . '/*/')))
    $modules = array();

foreach ($modules as $m)
{
    $name = substr(strstr($m,"/!sys/modules/"),14,-1);
    if(!array_key_exists($name,$permlist["modules"])){
        $p = &$permlist['modules'][$name];
        $xml;
        if(file_exists($m."meta.xml"))$xml = simplexml_load_file($m."meta.xml");
        switch($xml){
            case (int2bool((int) $xml->config)):
              $p["config"] = true;
            case (file_exists($m."module.php") && int2bool((int) $xml->createable)):
              $p["view"] = true;
            case (file_exists($m."editor.php") && int2bool((int) $xml->createable)):
              $p["edit"] = true;
        }
        if(count($p)<1) unset($permlist['modules'][$name]);
    }
}
if (!is_array($plugins = glob(__ADMIN_DIR__ . '/plugins/action.*')))
    $plugins = array();
foreach ($plugins as $m)
{
    $name = substr(strstr($m,"/action."),8,-4);
    if(!array_key_exists($name,$permlist["system"])){
       $permlist['system'][$name]["use"] = false;
    }
}


$m = menu(_CONTENTPATH_);
recursivePage($m,$n);
$permlist['pages'] = $n;


$smarty->assign('pages',menu(_CONTENTPATH_));
$smarty->assign('perms',$permlist);
$smarty->assign("groups",$session->user()->getGroupList());
return $smarty->fetch('config.tpl');
function recursivePage($m,&$n){
    if(!is_array($m)) return;

    $n[$m['adress']]=array("view"=> "false","edit"=>"false");
    foreach($m['children'] as $p){
       recursivePage($p,$n);
    }
}
?>
